package mianshixianchang;

public class Offer0 {
    public boolean isValid(String s) {
        if(s == null || s.equals("")){
            return  true;
        }

        int stackSize = 0;
        int strSize = s.length();

        for(int i = 0; i < strSize; i++){
            char ch = s.charAt(i);

            if(ch == '('){
                stackSize++;
            }

            if(ch == ')'){
                if(stackSize == 0){
                    return false;
                }
                stackSize--;
            }
        }

        return stackSize <= 0;
    }

    public static void main(String[] args) {
        System.out.println(new Offer0().isValid("())"));
        System.out.println(new Offer0().isValid("(())"));
    }
}